package top.wyz5204.controller;

import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import org.springframework.http.client.OkHttp3ClientHttpRequestFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.IOException;
import java.util.Objects;

//@Controller 把用户提交来的请求通过对URL的匹配，分配个不同的接收器，再进行处理，然后向用户返回结果
//@ResponseBody 将方法返回值绑定到 Web 响应主体
//@RestController @ResponseBody和@Controller组合注解，用于返回JSON字符串
//@RequestMapping 用来处理请求地址映射的注解
//@GetMapping 等价于@RequestMapping(value = “”,method = RequestMethod.GET)就是使用Get方法提交
@Controller
@RequestMapping("/juhe")
public class JHController {

    @GetMapping("/fapig")
    @ResponseBody
    public String fapig() throws IOException {
        OkHttpClient client = new OkHttpClient();
        Request request = new Request.Builder().url("http://apis.juhe.cn/fapig/douyin/billboard?type=hot_video&size=&key=3449b89378215c87d785353ee0da1d2b").build();
        Response execute = client.newCall(request).execute();
        return Objects.requireNonNull(execute.body()).string();
    }
}
